package exttable.dbclasses;

import dbutils.DbUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Created by IntelliJ IDEA.
 * User: Stat
 * Date: 13.04.12
 * Time: 12:41
 * To change this template use File | Settings | File Templates.
 */
public class DbFile {
    int fileId;
    String fileName;
    String fileEhtension;
    String sourceFileName;
    String tableName;
    String sumCRC32;

    public int getFileId() {
        return fileId;
    }

    public void setFileId(int fileId) {
        this.fileId = fileId;
    }

    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    public String getFileEhtension() {
        return fileEhtension;
    }

    public void setFileEhtension(String fileEhtension) {
        this.fileEhtension = fileEhtension;
    }

    public String getSourceFileName() {
        return sourceFileName;
    }

    public void setSourceFileName(String sourceFileName) {
        this.sourceFileName = sourceFileName;
    }

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    public String getSumCRC32() {
        return sumCRC32;
    }

    public void setSumCRC32(String sumCRC32) {
        this.sumCRC32 = sumCRC32;
    }

    public  DbFile(){

    }

    public static DbFile getDbFileById(int file_id){
        DbFile dbFile=null;
        Connection connGeneral=null;
        PreparedStatement psGeneral=null;
        ResultSet rs=null;

        try {
            connGeneral= DbUtils.getDBConnectionGeneral();
            psGeneral=connGeneral.prepareStatement("SELECT * FROM files WHERE file_id=?");
            psGeneral.setInt(1,file_id);
            rs=psGeneral.executeQuery();
            while (rs.next()){
                dbFile=new DbFile();
                dbFile.setFileId(rs.getInt("file_id"));
                dbFile.setFileName(rs.getString("file_name"));
                dbFile.setFileEhtension(rs.getString("file_ehtension"));
                dbFile.setSourceFileName(rs.getString("source_file_name"));
                dbFile.setTableName(rs.getString("table_name"));
                dbFile.setSumCRC32(rs.getString("sumCRC32"));
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        } catch (SQLException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
        return dbFile;
    }
}
